package com.example.teamtribe.main.club.manage.applyactivity;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.teamtribe.R;
import com.example.teamtribe.database.AcApply;
import com.example.teamtribe.database.User;
import com.example.teamtribe.utils.Utility;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AcAppAdapter extends RecyclerView.Adapter<AcAppAdapter.ViewHolder> {

    private List<AcApply> acApplies;

    public AcAppAdapter(List<AcApply> acApplies) {
        this.acApplies = acApplies;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_acapply, parent, false);
        final ViewHolder holder = new ViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        AcApply apply = acApplies.get(position);
        holder.tvDate.setText(apply.getDate());
        holder.tvName.setText(apply.getName());
        holder.tvPlace.setText(apply.getPlace());
        holder.tvSponsor.setText("赞助商：" + apply.getSponsor());
        holder.tvSphone.setText("赞助商电话：" + apply.getsPhone());
        User user = Utility.getT(apply.getUserId(), User.class);
        if (user != null) {
            holder.tvUser.setText("负责人：" + user.getName());
        }
        if (position == 0) {
            holder.topLine.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return acApplies.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tvTopLine)
        View topLine;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_user)
        TextView tvUser;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_place)
        TextView tvPlace;
        @BindView(R.id.tv_sponsor)
        TextView tvSponsor;
        @BindView(R.id.tv_sPhone)
        TextView tvSphone;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
